package leetcode;

/**
 * Created by Ghost on 2014/11/25 0025.
 */
public class Maximum_Product_Subarray {

    public int maxProduct(int[] A) {
        int n = A.length;
        int curMin = A[0];
        int curMax = A[0];
        int max = A[0];
        for(int i=1;i<n;i++){
            int a = curMin * A[i];
            int b = curMax * A[i];
            curMin = Math.min(Math.min(a,b),A[i]);
            curMax = Math.max(Math.max(a,b),A[i]);
            max = Math.max(max,curMax);
        }
        return max;
    }

    public static void main(String[] args) {
        Maximum_Product_Subarray maximum_product_subarray = new Maximum_Product_Subarray();
        int[] a = {-2, -7, 7, -2, -4, -2};
        System.out.println(maximum_product_subarray.maxProduct(a));
    }
}
